<template>
  <!--  接入规则  -->
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="规则名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入规则名称"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品类型" prop="productName">
        <el-select
          v-model="queryParams.productName"
          placeholder="产品类型"
          clearable
          style="width: 240px"
        >
          <el-option
            v-for="dict in productData"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="厂商" prop="productName">
        <el-select
          v-model="queryParams.firm"
          placeholder="厂商"
          clearable
          style="width: 240px"
        >
          <el-option
            v-for="dict in firmData"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"

          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >新增
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="roleList" :header-cell-style="{ background: '#F3F5FC' }" height="74%">
      <el-table-column label="序号" align="center" width="120">
        <template slot-scope="scop">
          {{ scop.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column label="规则名称" prop="name" :show-overflow-tooltip="true"/>
      <el-table-column label="接入产品" prop="sourceTemplateName" :show-overflow-tooltip="true"/>
      <el-table-column label="元数据" prop="storeTemplateName"/>
      <el-table-column label="操作" align="center"  class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
                   @click="handleUpdate(scope.row)"
          >编辑
          </el-button>
          <el-button
            size="mini"
            type="text"
                 @click="handleCopy(scope.row)"
          >复制
          </el-button>
          <el-button
            size="mini"
            type="text"
                @click="handleDelete(scope.row)"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改对话框 -->
    <!-- <editDialog ref="editRef" :title="title" :formData="formData"/> -->
  </div>
</template>

<script>
// import editDialog from '@/components/accessProduct/accessRules/emitDialog.vue'
import rulesData from './mockData/rulesData.json'

export default {
  name: 'accessRule',
  dicts: ['sys_normal_disable'],
  components: {  },
  data() {
    return {
      formData: {},
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 角色表格数据
      roleList: [],
      // 弹出层标题
      title: '',
      menuExpand: false,
      menuNodeAll: false,
      deptExpand: true,
      deptNodeAll: false,
      // 日期范围
      dateRange: [],
      // 数据范围选项
      dataScopeOptions: [
        {
          value: '1',
          label: '全部数据权限'
        },
        {
          value: '2',
          label: '自定数据权限'
        },
        {
          value: '3',
          label: '本部门数据权限'
        },
        {
          value: '4',
          label: '本部门及以下数据权限'
        },
        {
          value: '5',
          label: '仅本人数据权限'
        }
      ],
      // 菜单列表
      menuOptions: [],
      // 部门列表
      deptOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        roleName: undefined,
        roleKey: undefined,
        status: undefined,
        firm: undefined
      },
      // 表单参数
      form: {},
      defaultProps: {
        children: 'children',
        label: 'label'
      },
      productData: [{
        label: '网络检测',
        value: '10'
      }, {
        label: '敏感信息',
        value: '7'
      }, {
        label: '刻录审计',
        value: '4'
      }, {
        label: '打印审计',
        value: '3'
      }, {
        label: '接入控制',
        value: '6'
      }],
      // 厂商
      firmData: [{
        label: '泓科',
        value: '1'
      }, {
        label: '天融信',
        value: '2'
      }, {
        label: '北信源',
        value: '3'
      }, {
        label: '景天',
        value: '4'
      }, {
        label: '安天',
        value: '5'
      }]
    }
  },
  mounted() {
    this.getList()
  },
  methods: {
    /** 查询角色列表 */
    getList() {
      this.loading = false
      this.roleList = rulesData.page.list
      this.total = rulesData.page.totalCount
    },

    // 表单重置
    reset() {
      if (this.$refs.menu != undefined) {
        this.$refs.menu.setCheckedKeys([])
      }
      this.menuExpand = false,
        this.menuNodeAll = false,
        this.deptExpand = true,
        this.deptNodeAll = false,
        this.form = {
          roleId: undefined,
          roleName: undefined,
          roleKey: undefined,
          roleSort: 0,
          status: '0',
          menuIds: [],
          deptIds: [],
          menuCheckStrictly: true,
          deptCheckStrictly: true,
          remark: undefined
        }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.loading = true
      let _self = this
      setTimeout(function() {
        _self.getList()
      }, 1000)
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = []
      this.resetForm('queryForm')
      this.handleQuery()
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.$refs.editRef.isOpen = true
      this.$refs.editRef.active=0
      this.title = '添加'
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.$refs.editRef.isOpen = true
      this.$refs.editRef.active=0
      this.formData = row
      this.reset()
      this.title = '编辑'
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const name = row.name
      this.$modal.confirm('是否确认删除角色编号为"' + name + '"的数据项？').then(function() {
        return true
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess('删除成功')
      }).catch(() => {
      })
    },
    /** 复制 **/
    handleCopy(row) {
      this.$message({
        message: '复制成功',
        type: 'success'
      })
    }
  }
}
</script>
